# ----------- 构建前端 -----------
FROM node:20-alpine AS frontend-build
WORKDIR /frontend
COPY frontend/ ./
# 使用淘宝镜像安装pnpm
RUN npm install -g pnpm --registry=https://registry.npmmirror.com \
    && pnpm config set registry https://registry.npmmirror.com \
    && pnpm install \
    && pnpm run build

# ----------- 构建后端 -----------
FROM python:3.11-slim AS backend
WORKDIR /app
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
# 复制后端代码
COPY backend/ ./backend/
COPY requirements.txt ./
# 安装后端依赖（清华源）
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip \
    && pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# 复制前端构建产物到后端static目录
COPY --from=frontend-build /frontend/dist ./backend/static/

EXPOSE 8000
CMD ["uvicorn", "backend.fastapi_app:app", "--host", "0.0.0.0", "--port", "8000"]